// 封装购物车相关的API函数
import request from "@/utils/request";

/** 获取商品的最新详情(最新价格、库存、是否是有效商品)
* @param {String} skuId  skuId
* @returns 
*/
export const getNewCartGoods = (skuId) => {
    return request(`/goods/stock/${skuId}`, "get")
}

/** 获取商品对应的sku数据
* @param {String} skuId  skuId
* @returns 
*/
export const getGoodsSku = (skuId) => {
    return request(`/goods/sku/${skuId}`, "get")
}


/**
 * 合并购物车列表
 * @param {Array<object>} cartList  购物车列表
 * @param {String} object.skuId  skuId
 * @param {Boolean} object.selected  选中状态
 * @param {String} object.count  数量
 * @returns 
 */
export const mergeCart = (cartList) => {
    return request("/member/cart/merge", "post", cartList)
}

/**
 * 获取购物车列表
 * @returns 
 */
export const findCartList = () => {
    return request("/member/cart", "get")
}

/**
 * 加入购物车
 * @param {String} skuId  skuId
 * @param {String} count  加入购物车数量
 * @returns 
 */
export const insertCartList = ({ skuId, count }) => {
    return request("/member/cart", "post", { skuId, count })
}

/**
 * 删除购物车,支持批量
 * @param {Array<string>} ids  skuId的集合
 * @param {String} count  加入购物车数量
 * @returns 
 */
export const deleteCartList = (ids) => {
    return request("/member/cart", "delete", { ids })
}

/**
 * 修改购物车,支持(数量,状态)
* @param {String} skuId  skuId
 * @param {String} count  修改购物车数量
 * @param {Boolean} selected  选中状态
 * @returns 
 */
export const updateCartList = ({ skuId, selected, count }) => {
    return request(`/member/cart/${skuId}`, "put", { selected, count })
}

/**
 * 全选或者取消全选
 * @param {Array<string>} ids  skuId的集合
 * @param {Boolean} selected  选中状态
 * @returns 
 */
export const checkAllCartList = ({ selected, ids }) => {
    return request("/member/cart/selected", "put", { selected, ids })
}